const baseUrl = "http://localhost:3001";
const fetch = async (url, options) => {
  const reqUrl = baseUrl + url;
  return new Promise((resolve, reject) => {
    useFetch(reqUrl, { ...options })
      .then(({ data, error }) => {
        if (error.value) {
          reject(error.value);
          return;
        }
        const value = data.value;
        if (!value) {
          // 这里处理错误回调
          // reject(value)
          // $router.replace('/reject/' + value.status)
        } else {
          console.log('返回参数======================', value)
          resolve(value);
        }
      })
      .catch((err) => {
        reject(err);
      });
  });
};

export default new class Http {
  get(url, params) {
    return fetch(url, { method: "get", params });
  }
  post(url, params) {
    return fetch(url, { method: "post", params });
  }
  put(url, body) {
    return fetch(url, { method: "put", body });
  }
  delete(url, body) {
    return fetch(url, { method: "delete", body });
  }
};
